int ret = 0,tmp = 0;
void fun(string& num,char a1,char a2)
{
        bool t1 = true;
        tmp = 0;
        for(auto c = num.rbegin();c != num.rend();c++)
        {
            if(t1){
                if(*c != a1)
                {
                    tmp++;
                }
                else{
                    t1 = false;
                }
            }else{
                if(*c != a2){
                    tmp++;
                }
                else{
                    ret = min(ret,tmp);
                }
            }
        }
}
class Solution {
public:

    int minimumOperations(string num) {
        ret = num.size();
        ret = ret - (num.find('0') != string::npos);
        fun(num,'0','0');
        fun(num,'5','2');
        fun(num,'0','5');
        fun(num,'5','7');
        //ret = min(ret, int(num.size()-tmp));
        return ret;
    }
};